/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "zobjects_gtk.h"

ZlangInvokeFunction ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_string;
int ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_string( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guimessagedialog	*guimessagedialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow		*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common	*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	char						*message = NULL ;
	
	CallRuntimeFunction_string_GetStringValue( rt , in2 , & message , NULL );

	guimessagedialog_direct_prop->gtk_dialog = gtk_message_dialog_new( GTK_WINDOW(guiwindow_common->gtk_widget) , GTK_DIALOG_MODAL , GUIDIALOG_TYPE_INFO , GUIBUTTONS_OK , message ) ;
	/*
	gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG(guimessagedialog_direct_prop->gtk_dialog) , message );
	*/
	gtk_window_set_deletable( GTK_WINDOW(guimessagedialog_direct_prop->gtk_dialog) , FALSE );
	
	guimessagedialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guimessagedialog_direct_prop->gtk_dialog) ) ;

	CallRuntimeFunction_int_SetIntValue( rt , out1 , guimessagedialog_direct_prop->response );
	return 0;
}

ZlangInvokeFunction ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_int_string_string_int;
int ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_int_string_string_int( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guimessagedialog	*guimessagedialog_direct_prop = GetObjectDirectProperty(obj) ;
	struct ZlangObject				*in1 = GetInputParameterInLocalObjectStack(rt,1) ;
	struct ZlangObject				*in2 = GetInputParameterInLocalObjectStack(rt,2) ;
	struct ZlangObject				*in3 = GetInputParameterInLocalObjectStack(rt,3) ;
	struct ZlangObject				*in4 = GetInputParameterInLocalObjectStack(rt,4) ;
	struct ZlangObject				*in5 = GetInputParameterInLocalObjectStack(rt,5) ;
	struct ZlangObject				*out1 = GetOutputParameterInLocalObjectStack(rt,1) ;
	struct ZlangDirectProperty_guiwindow		*guiwindow_direct_prop = GetObjectDirectProperty(in1) ;
	struct ZlangDirectProperty_guiwidget_common	*guiwindow_common = (struct ZlangDirectProperty_guiwidget_common *)guiwindow_direct_prop ;
	int32_t						dialog_type ;
	char						*title = NULL ;
	char						*message = NULL ;
	int32_t						btns ;
	
	CallRuntimeFunction_int_GetIntValue( rt , in2 , & dialog_type );
	CallRuntimeFunction_string_GetStringValue( rt , in3 , & title , NULL );
	CallRuntimeFunction_string_GetStringValue( rt , in4 , & message , NULL );
	CallRuntimeFunction_int_GetIntValue( rt , in5 , & btns );

	if( btns == GUIBUTTONS_YES_NO_CANCEL )
	{
		guimessagedialog_direct_prop->gtk_dialog = gtk_message_dialog_new( GTK_WINDOW(guiwindow_common->gtk_widget) , GTK_DIALOG_MODAL , dialog_type , GTK_BUTTONS_NONE , title ) ;
		gtk_dialog_add_buttons( GTK_DIALOG(guimessagedialog_direct_prop->gtk_dialog)
						, "Yes" , GTK_RESPONSE_YES
						, "No" , GTK_RESPONSE_NO
						, "Cancel" , GTK_RESPONSE_CANCEL
						, NULL );
		gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG(guimessagedialog_direct_prop->gtk_dialog) , message );
	}
	else
	{
		guimessagedialog_direct_prop->gtk_dialog = gtk_message_dialog_new( GTK_WINDOW(guiwindow_common->gtk_widget) , GTK_DIALOG_MODAL , dialog_type , btns , title ) ;
		gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG(guimessagedialog_direct_prop->gtk_dialog) , message );
	}
	gtk_window_set_deletable( GTK_WINDOW(guimessagedialog_direct_prop->gtk_dialog) , FALSE );
	
	guimessagedialog_direct_prop->response = GtkDialogRun( rt , GTK_DIALOG(guimessagedialog_direct_prop->gtk_dialog) ) ;

	CallRuntimeFunction_int_SetIntValue( rt , out1 , guimessagedialog_direct_prop->response );
	return 0;
}

ZlangCreateDirectPropertyFunction ZlangCreateDirectProperty_guimessagedialog;
void *ZlangCreateDirectProperty_guimessagedialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guimessagedialog	*guimessagedialog_prop = NULL ;
	
	guimessagedialog_prop = (struct ZlangDirectProperty_guimessagedialog *)ZLMALLOC( sizeof(struct ZlangDirectProperty_guimessagedialog) ) ;
	if( guimessagedialog_prop == NULL )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_ALLOC , "alloc memory for entity" )
		return NULL;
	}
	memset( guimessagedialog_prop , 0x00 , sizeof(struct ZlangDirectProperty_guimessagedialog) );
	
	return guimessagedialog_prop;
}

ZlangDestroyDirectPropertyFunction ZlangDestroyDirectProperty_guimessagedialog;
void ZlangDestroyDirectProperty_guimessagedialog( struct ZlangRuntime *rt , struct ZlangObject *obj )
{
	struct ZlangDirectProperty_guimessagedialog	*guimessagedialog_direct_prop = GetObjectDirectProperty(obj) ;
	
	ZLFREE( guimessagedialog_direct_prop );
	
	return;
}

ZlangSummarizeDirectPropertySizeFunction ZlangSummarizeDirectPropertySize_guimessagedialog;
void ZlangSummarizeDirectPropertySize_guimessagedialog( struct ZlangRuntime *rt , struct ZlangObject *obj , size_t *summarized_obj_size , size_t *summarized_direct_prop_size )
{
	SUMMARIZE_SIZE( summarized_direct_prop_size , sizeof(struct ZlangDirectProperty_guimessagedialog) )
	return;
}

static struct ZlangDirectFunctions direct_funcs_guimessagedialog =
	{
		ZLANG_OBJECT_guimessagedialog , /* char *ancestor_name */
		
		ZlangCreateDirectProperty_guimessagedialog , /* ZlangCreateDirectPropertyFunction *create_entity_func */
		ZlangDestroyDirectProperty_guimessagedialog , /* ZlangDestroyDirectPropertyFunction *destroy_entity_func */
		
		NULL , /* ZlangFromCharPtrFunction *from_char_ptr_func */
		NULL , /* ZlangToStringFunction *to_string_func */
		NULL , /* ZlangFromDataPtrFunction *from_data_ptr_func */
		NULL , /* ZlangGetDataPtrFunction *get_data_ptr_func */
		
		NULL , /* ZlangOperatorFunction *oper_PLUS_func */
		NULL , /* ZlangOperatorFunction *oper_MINUS_func */
		NULL , /* ZlangOperatorFunction *oper_MUL_func */
		NULL , /* ZlangOperatorFunction *oper_DIV_func */
		NULL , /* ZlangOperatorFunction *oper_MOD_func */
		
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NEGATIVE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_NOT_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_BIT_REVERSE_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_PLUS_PLUS_func */
		NULL , /* ZlangUnaryOperatorFunction *unaryoper_MINUS_MINUS_func */
		
		NULL , /* ZlangCompareFunction *comp_EGUAL_func */
		NULL , /* ZlangCompareFunction *comp_NOTEGUAL_func */
		NULL , /* ZlangCompareFunction *comp_LT_func */
		NULL , /* ZlangCompareFunction *comp_LE_func */
		NULL , /* ZlangCompareFunction *comp_GT_func */
		NULL , /* ZlangCompareFunction *comp_GE_func */
		
		NULL , /* ZlangLogicFunction *logic_AND_func */
		NULL , /* ZlangLogicFunction *logic_OR_func */
		
		NULL , /* ZlangLogicFunction *bit_AND_func */
		NULL , /* ZlangLogicFunction *bit_XOR_func */
		NULL , /* ZlangLogicFunction *bit_OR_func */
		NULL , /* ZlangLogicFunction *bit_MOVELEFT_func */
		NULL , /* ZlangLogicFunction *bit_MOVERIGHT_func */
		
		ZlangSummarizeDirectPropertySize_guimessagedialog , /* ZlangSummarizeDirectPropertySizeFunction *summarize_direct_prop_size_func */
	} ;

ZlangImportObjectFunction ZlangImportObject_guimessagedialog;
struct ZlangObject *ZlangImportObject_guimessagedialog( struct ZlangRuntime *rt )
{
	struct ZlangObject	*obj = NULL ;
	struct ZlangObject	*prop = NULL ;
	struct ZlangFunction	*func = NULL ;
	int			nret = 0 ;
	
	nret = ImportObject( rt , & obj , ZLANG_OBJECT_guimessagedialog , & direct_funcs_guimessagedialog , sizeof(struct ZlangDirectFunctions) , NULL ) ;
	if( nret )
	{
		SET_RUNTIME_ERROR( rt , RUNTIME_ERROR , ZLANG_ERROR_LINK_FUNC_TO_ENTITY , "import object to global objects heap" )
		return NULL;
	}
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "INFO_TYPE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIDIALOG_TYPE_INFO );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "WARNING_TYPE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIDIALOG_TYPE_WARNING );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "ERROR_TYPE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIDIALOG_TYPE_ERROR );
	SetConstantObject( prop );
	
	prop = AddPropertyInObject( rt , obj , GetIntObjectInRuntimeObjectsHeap(rt) , "QUESTION_TYPE") ;
	if( prop == NULL )
		return NULL;
	CallRuntimeFunction_int_SetIntValue( rt , prop , GUIDIALOG_TYPE_QUESTION );
	SetConstantObject( prop );
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_string , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_string,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	func = AddFunctionAndParametersInObject( rt , obj , ZlangInvokeFunction_guimessagedialog_ModalOpenDialog_guiwindow_int_string_string_int , ZLANG_OBJECT_int , "ModalOpenDialog" , ZLANG_OBJECT_guiwindow,NULL , ZLANG_OBJECT_int,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_string,NULL , ZLANG_OBJECT_int,NULL , NULL ) ;
	if( func == NULL )
		return NULL;
	
	return obj ;
}

